/*
 * Copyright (c) 2018-2021 Tero Hänninen.
 * SPDX-License-Identifier: BSD-2-Clause
 */

module abi;
module ast;
module astfree;
module astdump;
module bbqueue;
module config;
module console;
module debugprint;
module dyna;
module drive;
module errors;
module global;
module lex;
module llvm;
module llvmffi;
module mangle;
module mir;
module mirexp;
module mirgen;
module mirvm;
module monopool;
module parse;
module peekbuf;
module platform;
module pool;
module printcrutch;
module semantic;
module semexp;
module setups;
module stash;
module strutil;
module symtab;
module sys;     // platform specific definitions
module system;  // cross-platform api
module tokens;
module type;
module typeinfo;
module typeinfomap;
module xxhash;
#setup[unittest]
module test;    // contains main function

import std.mem;
import std.dyna;
import self.drive;
import self.global;
import self.strutil;

#setup[!unittest]
int main(int argc, const ubyte** argv)
{
    STASH = stash.init_populated();

    const ubyte[]* args = xmalloc(ubyte[].sizeof * argc);

    for (int i; i < argc; i++)
        args[i] = argv[i][0 .. strlen(argv[i])];

    CLIdef~ defs = dyna.empty(CLIdef);

    ACTION action = parse_config_and_args(args[0..argc], &defs);

    switch (action) {
    case ACTION.CONT:
        return compile(defs);
    case ACTION.EXIT:
        return STATUS.ok;
    case ACTION.ERROR:
        return STATUS.error;
    }
}
